const express = require("express");
const router = express.Router();
const app = new express();
const path = require('path');
const bodyParser = require("body-parser");

app.use(bodyParser.json());

// 引用后台单个API路径
const apiCommon = require('./modules/common');

//设置跨域访问
app.all('*', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "*");
    res.header("Access-Control-Allow-Credentials", "true");
    res.header("Access-Control-Allow-Headers", "Content-Type,Access-Token,adminid");
    res.header("Access-Control-Expose-Headers", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With,token");
    next();
});

app.use('/api/common', apiCommon) //共用接口

//配置uploads目录为图片根目录
app.use('/uploads', express.static('uploads'));

//配置服务端口
const server = app.listen(8199, 'localhost', function () {
    const host = server.address().address;
    const port = server.address().port;
    console.log('后端api接口地址是：http://%s:%s', host, port);
});